package com.cx.common.core.dto.request;

import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.*;
import lombok.experimental.Accessors;
import lombok.experimental.SuperBuilder;

import javax.validation.Valid;

@ApiModel(description = "分页请求对象")
@SuperBuilder
@EqualsAndHashCode(callSuper = true)
@Accessors(chain = true)
@Data
@NoArgsConstructor
@AllArgsConstructor
public class PageReq<T> extends BaseReq {

    public static final int DEFAULT_PAGE_INDEX = 1;
    public static final int DEFAULT_PAGE_SIZE = 10;
    private static final long serialVersionUID = 1L;
    @Valid
    @ApiModelProperty(value = "请求参数，可为基本类型（包装类），可以为其它可序列化对象", required = true)
    private T data;

    @ApiModelProperty(value = "当前页 默认第1页", required = true, example = "1")
    @Builder.Default
    private int pageIndex = DEFAULT_PAGE_INDEX;

    @ApiModelProperty(value = "当前页大小 默认10条", required = true, example = "10")
    @Builder.Default
    private int pageSize = DEFAULT_PAGE_SIZE;

    @ApiModelProperty(value = "是否查询全部 此参数为true则会忽略pageIndex和pageSize参数", example = "false")
    @Builder.Default
    private boolean fetchAll = false;

    public static <T> PageReq<T> create(long time, String ip,
                                        int pageIndex, int pageSize, boolean fetchAll, String id, Integer role, Byte system) {
        return PageReq.<T>builder()
                .time(time).ip(ip).id(id).role(role).system(system)
                .pageIndex(pageIndex)
                .pageSize(pageSize)
                .fetchAll(fetchAll)
                .build();
    }

    public static <T> PageReq<T> create() {
        return PageReq.<T>builder()
                .build();
    }
}
